@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>评价管理</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form action="" method="GET">
                                {{csrf_field()}}
                                <div class="col-sm-12">
                                    <div class="input-group fl mr10 mb5">
                                        <input name="product_name" type="text" placeholder="请输入商品名称" class="input-sm form-control" value="{{array_get($search_params, 'product_name')}}">
                                    </div>
                                    <div class="input-group fl mr10 mb5">
                                        <input name="shop_name" type="text" placeholder="请输入商铺名称" class="input-sm form-control" value="{{array_get($search_params, 'shop_name')}}">
                                    </div>
                                    <div class="input-group fl mr10 mb5">
                                        <input name="user_name" type="text" placeholder="请输入评价人" class="input-sm form-control" value="{{array_get($search_params, 'user_name')}}">
                                    </div>
                                    {{--<div class="input-group fl mr10 mb5">
                                        <input type="text" placeholder="评价评分" class="input-sm form-control">
                                    </div>--}}
                                    <div class="input-group fl mr10 mb5">
                                        <select class="form-control m-b" name="check_status">
                                            <option value="">状态</option>
                                            <option value="1" {{array_get($search_params, 'check_status') == 1 ? 'selected' : ''}}>未审核</option>
                                            <option value="2" {{array_get($search_params, 'check_status') == 2 ? 'selected' : ''}}>正常</option>
                                            <option value="3" {{array_get($search_params, 'check_status') == 3 ? 'selected' : ''}}>无效</option>
                                        </select>
                                    </div>
                                    <div class="input-group fl mr10 mb5">
                                        <input name="created_at[start]" placeholder="开始日期" class="input-sm form-control layer-date" id="start" value="{{array_get($search_params, 'created_at.start')}}">
                                    </div>
                                    <div class="input-group fl mr10 mb5"><p class="form-control-static">至</p></div>
                                    <div class="input-group fl mr10 mb5">
                                        <input name="created_at[end]" placeholder="结束日期" class="input-sm form-control layer-date" id="end" value="{{array_get($search_params, 'created_at.end')}}">
                                    </div>
                                    <button type="submit" class="btn btn-sm btn-primary fl mb5">查询</button>
                                </div>
                            </form>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                            <thead>
                                <tr>
                                    <th>评价人</th>
                                    <th>评分</th>
                                    <th>店铺</th>
                                    <th>评价内容</th>
                                    <th>订单号码</th>
                                    <th>评价商品</th>
                                    <th>评价时间</th>
                                    <th>状态</th>
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            @if($list)
                                @foreach($list as $comment)
                                    <tr>
                                        <td>{{array_get($comment, 'user.name', '-')}}</td>
                                        <td>{{number_format(($comment['product_comment'] + $comment['seller_comment'] + $comment['logistics_comment']) / 3,1)}}</td>
                                        <td>{{array_get($comment, 'order_product.shop_name', '-')}}</td>
                                        <td>{{$comment['comment']}}</td>
                                        <td>{{$comment['order_code']}}</td>
                                        <td>{{array_get($comment, 'order_product.product_name', '-')}}</td>
                                        <td>{{date('Y/m/d', strtotime($comment['created_at']))}}</td>
                                        <td>{{$comment['check_status'] == 3 ? '无效' : '正常'}}</td>
                                        <td class="text-center">
                                            @if($comment['check_status'] <= 2)
                                                <a class="btn-xs btn-warning check_order_invalid" data-id="{{$comment['id']}}">
                                                    无效@if($comment['check_status'] == 1) [未审核] @endif
                                                </a>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <tr class="no-records-found center"><td colspan="8">没有找到匹配的记录</td></tr>
                            @endif
                            </tbody>
                        </table>
                        <div class="row">
                            @include('Admin.common.paginate', ['page' => $page])
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="{{asset('js/plugins/layer/laydate/laydate.js')}}"></script>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>

    <script>
        var cancel_order = '/foradmin/order_product_comment/{id}';

        //日期范围限制
        var start = {
            elem: '#start',
            format: 'YYYY-MM-DD hh:mm:ss',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY-MM-DD hh:mm:ss',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
        //查看订单
        $('.check_order').click(function(){
            var url = '/order/details';//前端模板测试
            //var url = '/order/details/' + $(this).attr('data-id');//前端正式
            var title = '订单详情';
            open_page(url, title);//打开新页面
            /*$(window.parent.document).find('.J_menuTabs .page-tabs-content a').removeClass('active');
            $(window.parent.document).find('.J_menuTabs .page-tabs-content').append('<a href="javascript:;" class="J_menuTab active" data-id="'+url+'">'+title+' <i class="fa fa-times-circle"></i></a>');
            // 添加选项卡对应的iframe
            var str1 = '<iframe class="J_iframe" name="iframe' + $(this).attr('data-id') + '" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url + '" seamless></iframe>';
            $(window.parent.document).find('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(str1);*/
        })

        //设为无效
        $('.check_order_invalid').click(function(){
            var comment_id = $(this).attr('data-id');
            var url = cancel_order.replace('{id}', comment_id);
            layer.confirm('是否设为无效？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: url,
                    type: 'PUT',
                    dataType: 'json',
                    data: {'type': 'invalid'},
                    success: function (data) {
                        if (0 == data.code) {
                            layer.alert(data.message, {
                                icon: 1
                            }, function () {
                                location.reload();
                            });
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    },
                });
            }, function (index, layero) {
                layer.close(index);
            });
        })
    </script>
@endsection
